﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Epona.Domain.Query.Impl
{
    public abstract class AbstractCriterion:IQueryCriterion
    {
        public string ROOT_ALIAS { get{return "RootEntity";}}

        protected string QueryString;

        public virtual IQueryCriterion And(IQueryCriterion criterion)
        {
            return new AndCriterion(new IQueryCriterion[]{ this,criterion });
        }

        public virtual IQueryCriterion Or(IQueryCriterion criterion)
        {
            return new OrCriterion(new IQueryCriterion[] { this, criterion });
        }

        public virtual IQueryCriterion Not()
        {
            return new NotCriterion(this);
        }

        public virtual bool IsEmpty()
        {
            return false;
        }

        public virtual string ToQueryString()
        {
            return QueryString;
        }

        public virtual NamedParameters GetParameters()
        {
            throw new NotImplementedException();
        }

        protected IList<IQueryCriterion> RemoveNullOrEmptyCriterion(IQueryCriterion[] criterions)
        {
            IList<IQueryCriterion> results = new List<IQueryCriterion>();
            foreach(IQueryCriterion each in criterions)
            {
                if(each==null||each.IsEmpty())
                {
                    continue;
                }
                results.Add(each);
            }
            return results;
        }
    }
}
